package sist.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.text.TabExpander;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.document.AbstractPdfView;

import sist.bean.PageRank;

import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.PdfWriter;

//pdf
@Component
public class PageReportView extends AbstractPdfView{

	@Override
	protected void buildPdfDocument(Map<String, Object> model, Document document,
			PdfWriter writer, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		List<PageRank>list=(List<PageRank>) model.get("pdfModel");
		Table table=new Table(4,list.size()+1);
		table.setPadding(5);
		
		Cell cell=new Cell(new Paragraph("CNT"));
			 cell.setHeader(true);
			 table.addCell(cell);
		
			 cell=new Cell(new Paragraph("EMAIL"));
			 cell.setHeader(true);
			 table.addCell(cell);
			 
			 cell=new Cell(new Paragraph("NAME"));
			 cell.setHeader(true);
			 table.addCell(cell);
			 
			 cell=new Cell(new Paragraph("ADDRESS"));
			 cell.setHeader(true);
			 table.addCell(cell);
			 
			 table.endHeaders();
			 
			 for(PageRank r:list){
				 table.addCell(Integer.toString(r.getCnt()));
				 table.addCell(r.getEmail());
				 table.addCell(r.getName());
				 table.addCell(r.getAddress());
				 
			 }
			 
			 document.add(table);
	}
	
}
